// PGLEvent.cpp: implementation of the CPGLEvent class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include <pgl/mfc/pglmfcinclude.h>
#include <pgl/mfc/PGLEvent.h>
#include <pgl/mfc/PGLMFCGlobal.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPGLEvent::CPGLEvent()
: m_pGfx(NULL), m_pMouse(NULL), m_pParent(NULL)
{

}

CPGLEvent::~CPGLEvent()
{

}

bool CPGLEvent::IsValid() const
{
	return (m_pGfx!=NULL) && (m_pMouse!=NULL) && (m_pParent!=NULL) && (m_pRegion) && (m_pHelper!=NULL);
}


void CPGLEvent::SetRegion(long uRegionID)	
{	
	// check if the same as previuos
	if (m_pRegion && m_pRegion->CheckID(uRegionID))
		return;

	m_pRegion=CPGLRegionPoolSingleton::Find( uRegionID);
};


void CPGLPropEvent::OnRButtonDown(UINT nFlags, CPoint point) 
{
    if (!IsValid())
        return;

    CPGLRegionStPtr pRegion(GetRegion());

    if (!pRegion)
        return;

    while (pRegion->GetParent())
        pRegion=pRegion->GetParent();

    HINSTANCE hInst = AfxGetResourceHandle();
    AfxSetResourceHandle(CPGLMFCGlobal::GetInstance());

    CPGLAllPropsDlg propDlg;

    propDlg.SetRegion(pRegion);
    propDlg.DoModal();
    // redraw dialog
    GetHelper()->SetDirty();
    GetParent()->InvalidateRect(NULL,FALSE);

    AfxSetResourceHandle(hInst);
}